package leetcode.doublepointer;

import java.util.Arrays;

public class MoveZeroes {
    public static void main(String[] args) {
            int[] data = {1,2,0,3,5,7,0,7};
        moveZeroes2(data);
        System.out.println(Arrays.toString(data));
    }
    public static void moveZeroes(int[] nums) {
        int index = 0;
        int[] temp = new int[nums.length];
        for (int i =0;i<nums.length;i++){
            if (nums[i]!=0){
                temp[index++] = nums[i];
            }
        }
//        System.out.println(Arrays.toString(temp));
        System.arraycopy(temp,0,nums,0,nums.length);

    }

    //双指针---快慢指针
    public static void moveZeroes2(int[] nums) {
        int j =0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i]!=0){
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
                j++;
            }
        }
    }

}
